function Bernoulli3D2vtk(Node,Element,U,Scale,filename)
U = full(U);
UXYZ =  U(1:6:end); UXYZ(:, 2) =  U(2:6:end); UXYZ(:, 3) =  U(3:6:end); 
Node = Node + Scale * UXYZ;

num_nodes = size(Node, 1);
num_elements = size(Element, 1);

filePath1 = fullfile('output', strcat(filename,'-Scale-',num2str(Scale),'.vtk'));
vtk_file = fopen(filePath1,'w');

% 写入 VTK 文件头
fprintf(vtk_file, '# vtk DataFile Version 3.0\n');
fprintf(vtk_file, 'Finite Element Results\n');
fprintf(vtk_file, 'ASCII\n');
fprintf(vtk_file, 'DATASET UNSTRUCTURED_GRID\n');

% 写入节点坐标

fprintf(vtk_file, 'POINTS %d float\n', num_nodes);
for i = 1:num_nodes
    fprintf(vtk_file, '%f %f %f\n', Node(i, 1), Node(i, 2),Node(i, 3));
end
% 写入单元信息

fprintf(vtk_file, 'CELLS %d %d\n', num_elements, num_elements * 3);
for i = 1:num_elements
    fprintf(vtk_file, '2 %d %d\n', Element(i, 1) - 1, Element(i, 2) - 1);
end

% 写入单元类型
fprintf(vtk_file, 'CELL_TYPES %d\n', num_elements);
for i = 1:num_elements
    fprintf(vtk_file, '3\n'); % 2 节点线元素
end

%%%%%%%%%%%%%%%%%%%%%%%%POINT_DAT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 写入位移数据
fprintf(vtk_file, 'POINT_DATA %d\n', num_nodes);
fprintf(vtk_file, 'SCALARS U float 3\n');
fprintf(vtk_file, 'LOOKUP_TABLE default\n');
for i = 1:num_nodes
    fprintf(vtk_file, '%f %f %f \n', U(i * 6 - 5), U(i * 6-4),U(i * 6-3));
end

fclose(vtk_file);
end
